from data_define import *
# 创建商品对象
commodity1 = Commodity("火鸡面", "件", 4.5)
commodity2 = Commodity("可口可乐", "瓶", 3)
commodity3 = Commodity("脉动", "瓶", 5)
commodity4 = Commodity("薯片", "袋", 4)
commodity5 = Commodity("开心果", "斤", 32)
commodity6 = Commodity("笔记本", "本", 5)
commodity7 = Commodity("无线蓝牙耳机", "件", 288)
commodity8 = Commodity("草稿纸", "本", 2)
commodity9 = Commodity("高数大礼包", "件", 88)
commodity10 = Commodity("陶瓷茶杯", "件", 32)

# 创建销售统计实例
sales_stats = Sale_Statistics()
sales_stats.add_commodity(commodity1)
sales_stats.add_commodity(commodity2)
sales_stats.add_commodity(commodity3)
sales_stats.add_commodity(commodity4)
sales_stats.add_commodity(commodity5)
sales_stats.add_commodity(commodity6)
sales_stats.add_commodity(commodity7)
sales_stats.add_commodity(commodity8)
sales_stats.add_commodity(commodity9)
sales_stats.add_commodity(commodity10)


while True:
    print("1. 输入/修改/删除商品信息")
    print("2. 销售统计")
    print("3. 营业结束")
    choice = input("请选择功能：")

    if choice == "1":
        print("当前商品信息：")
        sales_stats.display_commodities()
        action = input("请选择操作（a. 输入商品信息 b. 修改商品信息 c. 删除商品信息）：")

        if action == "a":
            name = input("请输入商品名称：")
            unit = input("请输入计量单位：")
            price = float(input("请输入单价："))
            new_commodity = Commodity(name, unit, price)
            sales_stats.add_commodity(new_commodity)
            print("商品信息已添加!")

        elif action == "b":
            name = input("请输入要修改的商品名称：")
            for commodity in sales_stats.commodities:
                if commodity.name == name:
                    new_name = input("请输入新的商品名称（留空表示不修改）：")
                    new_unit = input("请输入新的计量单位（留空表示不修改）：")
                    new_price = input("请输入新的单价（留空表示不修改）：")

                    if new_name:
                        commodity.name = new_name
                    if new_unit:
                        commodity.unit = new_unit
                    if new_price:
                        commodity.price = float(new_price)

                    print("商品信息已修改!")
                    break
            else:
                print("未找到该商品!")

        elif action == "c":
            name = input("请输入要删除的商品名称：")
            sales_stats.remove_commodity(name)
            if not list(filter(lambda item: item.name == goods, sales_stats.commodities)):
                print('该商品不存在')
            else:
                print("商品信息已删除!")

        else:
            print("请输入有效操作！")
    elif choice == "2":
        sales_stats.display_commodities()
        while True:
            goods = input("请输入商品名称（输入-1结束本次购物）：")
            if not list(filter(lambda item: item.name == goods, sales_stats.commodities)):
                print('该商品不存在')
                continue

            if goods == "-1":
                break
            quantity = int(input("请输入购买数量："))
            sales_stats.sell_commodity(goods, quantity)
        sales_stats.display_sales_statistics()
    elif choice == "3":
        sales_stats.display_sales_statistics()
        break
    else:
        print("请输入有效选项")
